package com.huawei.appgallery.appcomment.ui.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.huawei.appgallery.appcomment.ui.view.SortSpinner.e;
import com.huawei.appgallery.appcomment.widget.SpinnerAdapter;
import o.bcg;
import o.bcg.c;
import o.bcg.f;
import o.bcg.h;
import o.beb;
import o.doo;
import o.epo;
import o.evk;
import o.fo;

public class CommentTitleView extends LinearLayout implements OnItemSelectedListener, com.huawei.appgallery.appcomment.ui.view.SortSpinner.d, e {
    private SpinnerAdapter ʻ;
    private int ʼ;
    private int ʽ;
    private beb ˊ;
    private SortSpinner ˋ;
    private TextView ˎ;
    private boolean ˏ;
    private SortSpinner ॱ;
    private SpinnerAdapter ॱॱ;
    private String ᐝ;

    public enum d {
        None,
        HotComment,
        AllComment
    }

    public void setIsSpinnerClick(boolean z) {
        this.ˏ = z;
    }

    public CommentTitleView(Context context) {
        this(context, null);
    }

    public CommentTitleView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public CommentTitleView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ᐝ = "";
        this.ʼ = 1;
        this.ʽ = 0;
        ˎ(context);
    }

    private void ˎ(Context context) {
        ((LayoutInflater) context.getSystemService("layout_inflater")).inflate(o.bcg.d.ˋॱ, this, true);
        this.ˎ = (TextView) findViewById(bcg.e.ꜝ);
        ˊ(context);
        ˏ();
        setOrientation(1);
    }

    private void ˊ(Context context) {
        this.ˏ = false;
        this.ˋ = (SortSpinner) findViewById(bcg.e.ﹳ);
        this.ॱ = (SortSpinner) findViewById(bcg.e.ʹ);
        r0 = new String[7];
        r0[2] = getContext().getResources().getQuantityString(f.ॱ, 5, new Object[]{Integer.valueOf(5)});
        r0[3] = getContext().getResources().getQuantityString(f.ॱ, 4, new Object[]{Integer.valueOf(4)});
        r0[4] = getContext().getResources().getQuantityString(f.ॱ, 3, new Object[]{Integer.valueOf(3)});
        r0[5] = getContext().getResources().getQuantityString(f.ॱ, 2, new Object[]{Integer.valueOf(2)});
        r0[6] = getContext().getResources().getQuantityString(f.ॱ, 1, new Object[]{Integer.valueOf(1)});
        String[] strArr = new String[]{getContext().getString(h.ᶥ), getContext().getString(h.ॱˈ), getContext().getString(h.ꓸ)};
        this.ॱॱ = new SpinnerAdapter(context, r0);
        this.ˋ.setAdapter(this.ॱॱ);
        this.ʻ = new SpinnerAdapter(context, strArr);
        this.ॱ.setAdapter(this.ʻ);
    }

    private void ˏ() {
        this.ॱ.setExtendClick(this);
        this.ॱ.setOnItemSelectedListener(this);
        this.ॱ.setRenderReadyListener(this);
        this.ˋ.setExtendClick(this);
        this.ˋ.setRenderReadyListener(this);
        this.ˋ.setOnItemSelectedListener(this);
    }

    public void setTitleViewByType(d dVar) {
        if (dVar == d.AllComment) {
            this.ˎ.setText(getContext().getString(h.ॱʼ));
            this.ˋ.setVisibility(0);
            this.ॱ.setVisibility(0);
        }
    }

    public void setOnFilterListener(beb o_beb) {
        this.ˊ = o_beb;
    }

    public void setFilterChecked(String str, int i, int i2) {
        int ˊ = ˊ(str, i2);
        int ˋ = ˋ(i);
        if (!(ˊ == -1 && ˋ == -1)) {
            this.ˋ.setSelection(ˊ);
            this.ॱ.setSelection(ˋ);
        }
        this.ᐝ = str;
        this.ʼ = i;
        this.ʽ = i2;
    }

    private int ˊ(String str, int i) {
        if (TextUtils.isEmpty(str)) {
            return 0;
        }
        if ("1".equals(str)) {
            return 1;
        }
        if ("3".equals(str)) {
            return 7 - i;
        }
        return -1;
    }

    private int ˋ(int i) {
        switch (i) {
            case 1:
                return 0;
            case 2:
                return 1;
            case 3:
                return 2;
            default:
                return -1;
        }
    }

    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long j) {
        if (!this.ˏ) {
            return;
        }
        if (doo.ˊ(getContext())) {
            int id = adapterView.getId();
            if (bcg.e.ﹳ != id) {
                if (bcg.e.ʹ == id) {
                    switch (i) {
                        case 0:
                            this.ʼ = 1;
                            break;
                        case 1:
                            this.ʼ = 2;
                            break;
                        case 2:
                            this.ʼ = 3;
                            break;
                        default:
                            break;
                    }
                }
            }
            switch (i) {
                case 0:
                    this.ᐝ = "";
                    break;
                case 1:
                    this.ᐝ = "1";
                    break;
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                    this.ᐝ = "3";
                    this.ʽ = 7 - i;
                    break;
            }
            this.ˊ.ˋ(this.ᐝ, this.ʼ, this.ʽ);
            return;
        }
        evk.ˋ(getContext(), getContext().getResources().getString(h.ᐝʽ), 0).ˋ();
    }

    public void onNothingSelected(AdapterView<?> adapterView) {
    }

    public void ˊ() {
        this.ˏ = true;
    }

    public void ॱ(int i) {
        this.ॱॱ.setImmer(true);
        this.ʻ.setImmer(true);
        Drawable ˊ = fo.ˊ(getContext(), c.ॱˊ);
        Drawable ˊ2 = fo.ˊ(getContext(), c.ॱˊ);
        this.ॱॱ.setTextColor(i);
        this.ʻ.setTextColor(i);
        this.ˋ.setBackground(epo.ॱ(ˊ, i));
        this.ॱ.setBackground(epo.ॱ(ˊ2, i));
    }
}
